package web.backend;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import entity.Easybuy_news;
import entity.Easybuy_order_detail;
import service.EasyBuyNewsService;
import service.Impl.EasyBuyNewsServiceImpl;
import utils.PageUtils;

/**
 * Servlet implementation class AdminNewsServlet
 */
public class AdminNewsServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	private EasyBuyNewsService service=new EasyBuyNewsServiceImpl();
       
    
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		String action=request.getParameter("action");
		switch (action) {
		case "queryNewsList":
			queryNewsList(request,response);
			break;

		default:
			break;
		}
	}

	private void queryNewsList(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		int currpage=Integer.parseInt(request.getParameter("currpage"));
		int pagesize=6;
		
		PageUtils<Easybuy_news> utils=service.newsList(currpage, pagesize);
		request.setAttribute("utils", utils);
		utils.setPageindex(currpage);
		request.getRequestDispatcher("/backend/news/NewsList.jsp").forward(request, response);
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
